﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:personalplaner.common.controls"
                    xmlns:k="clr-namespace:personalplaner.common.themes">

    <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
        <Border Name="Border" Background="Transparent" Margin="5">
            <Path SnapsToDevicePixels="True" IsHitTestVisible="False" Name="Arrow" Fill="#0FFF" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Right" VerticalAlignment="Center" Data="M 0 0 L 0 8 L 5 4 Z" Stroke="{DynamicResource {x:Static k:ResourceKeys.GlyphBrush}}" StrokeThickness="0.5">
                <Path.RenderTransform>
                    <RotateTransform Angle="0" />
                </Path.RenderTransform>
            </Path>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="False">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" To="180" DecelerationRatio="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation  Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" AccelerationRatio="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="#81F5F5F5"/>
                <Setter TargetName="Arrow" Property="Fill" Value="#81F5F5F5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


    <Style TargetType="Expander" x:Key="ContentExpander">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <Border BorderBrush="{DynamicResource {x:Static k:ResourceKeys.CollapsiblePanelBorderBrush}}" 
                            Background="{DynamicResource {x:Static k:ResourceKeys.CollapsiblePanelBackgroundBrush}}" 
                            BorderThickness="0,0,1,1" CornerRadius="1" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border Name="Border" BorderThickness="0,1,0,1" CornerRadius="1" VerticalAlignment="Top" Height="25"
                                    BorderBrush="{DynamicResource {x:Static k:ResourceKeys.CollapsiblePanelHeaderBorderBrush}}" 
                                    Background="{DynamicResource {x:Static k:ResourceKeys.CollapsiblePanelHeaderBackgroundBrush}}" >
                                <Grid>
                                    <ToggleButton Margin="8,0,4,0" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" />
                                </Grid>
                            </Border>

                            <Grid Grid.Row="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0" Name="ContentColumn"/>
                                </Grid.ColumnDefinitions>
                                <ContentPresenter ContentSource="Content" />
                            </Grid>

                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="False">
                            <Setter TargetName="ContentColumn" Property="Width" Value="{Binding ElementName=Content,Path=DesiredWidth}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="#81F5F5F5"/>
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="Border" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsExpanded" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                            <Setter TargetName="Border" Property="Cursor" Value="Hand" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:CollapsiblePanel}">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CollapsiblePanel}">
                    <Expander Style="{StaticResource ContentExpander}" 
                              ExpandDirection="{TemplateBinding ExpandDirection}"
                              IsExpanded="{Binding Path=IsCollapsed, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" >
                        <Border Margin="{TemplateBinding Padding}">
                            <DockPanel IsItemsHost="True" x:Name="PART_Presenter"/>
                        </Border>
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>